#!/usr/bin/perl
#act_vgconfig.cgi
require './lvm-lib.pl';
&ReadParse();
my ($vgname, $err_msg, $pv, $size, $mark);

$vgname = $in{'vgname'};
$mark = $in{'adrm'};
if($mark == 0){
	$pv = $in{'vgpv'};
}
elsif($mark == 1){
	$pv = $in{'freepv'};
}
else{
	$err_msg = "you must choose a way";
	goto ERROR_OUT;
}
if(!$vgname || !($vgname =~ /\S/)){
#	$err_msg = "No VG name! You must give it.";
	#goto ERROR_OUT;
}

@vginfo = get_vg_info();
foreach $vg (@vginfo) {
	if ($vg->{'vg'} eq $vgname) {
		$err_msg = $vgname."VG name used. Please change it.";
		#goto ERROR_OUT;
	}
}
my $rc;
if ($mark) {
	$rc = extend_vg($vgname, $pv);
}
else {
	$rc = reduce_vg($vgname, $pv);	
}
if(!$rc){
	&redirect("index.cgi");
}else{
	$err_msg = $text{'err_configvg'}; #"VG config failed.";
	goto ERROR_OUT;
}
return;
ERROR_OUT:
&error_setup($text{'crt_err_title'});
&error($err_msg);
